package com.rui.patterns.prototype.test1;

import java.io.*;

/**
 * @author : [锐神NO.3]
 * @version : [v1.0]
 * @className : CitationTest
 * @createTime : [2022/2/20 17:44]
 * @description : [描述该类的功能]
 */

public class CitationTest {
    public static void main(String[] args) throws Exception {

        //1.创建原型对象
        Citation citation = new Citation();

        //创建张三学生对象
        Student stu = new Student();
        stu.setName("张三");
        citation.setStudent(stu);

        //创建对象输出流
        ObjectOutputStream oos = new ObjectOutputStream(
                new FileOutputStream("D:\\StudyProject\\IdeaProject\\design_patterns\\src\\main\\java\\com\\rui\\patterns\\prototype\\test1\\robin\\a.txt")
        );

        //写对象
        oos.writeObject(citation);

        //释放资源
        oos.close();

        //创建对象输入流对象
        ObjectInputStream ois = new ObjectInputStream(
                new FileInputStream("D:\\StudyProject\\IdeaProject\\design_patterns\\src\\main\\java\\com\\rui\\patterns\\prototype\\test1\\robin\\a.txt")
        );

        //读对象
        Citation citation1 = (Citation) ois.readObject();

        //对象输入流对象释放资源
        ois.close();

        citation1.getStudent().setName("李四");

        citation.show();
        citation1.show();
    }
}
